package com.xinruke.hostels.central.manage.interfaces.api;

import com.xinruke.hostels.central.manage.interfaces.dto.*;
import com.xinruke.hostels.central.manage.interfaces.dto.sensitiveword.SensitiveWordCheckDTO;
import com.xinruke.hostels.central.manage.interfaces.dto.sensitiveword.SensitiveWordCheckResultDTO;
import com.xinruke.hostels.common.fallback.FeignFallback;
import com.xinruke.hostels.common.po.YwJiudian;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName CentralManageFallback
 * @CreateDate 2019/6/13
 * @Author FengXinQiang
 * @Version V1.0.0.0
 * @Decription 酒店信息API熔断处理
 */
@Component
@Slf4j
public class CentralManageFallback implements FallbackFactory<CentralManageAPI> {

    @Autowired
    private FeignFallback feignFallback;

    @Override
    public CentralManageAPI create(Throwable throwable) {
        log.error("系统异常", throwable);

        return new CentralManageAPI() {
            @Override
            public ResultVO<RowsDataVO<HotelPersonalQueryResultDTO>> getHotelInfoList(HotelPersonalQueryDTO hotelInfoQueryDTO) {
                return feignFallback.doFallback(CentralManageFallback.class, "getPersonalHotelInfoList", "查询酒店信息");
            }

            @Override
            public List<YwJiudian> getAllHotel(HotelAllQueryDTO allQueryDTO) {
                log.warn("熔断处理，className[" + CentralManageFallback.class.toString() + "]methodName[getAllHotel]");

                return new ArrayList<>();
            }

            @Override
            public ResultVO<HotelInfoDetailQueryResultDTO> getHotelInfoDtail(HotelInfoDetailQueryDTO hotelDetailQueryDTO) {
                return feignFallback.doFallback(CentralManageFallback.class, "getHotelInfoDtail", "查询酒店详情");

            }

            @Override
            public ResultVO<SensitiveWordCheckResultDTO> check(SensitiveWordCheckDTO params) {
                return feignFallback.doFallback(CentralManageFallback.class, "check", "敏感词校验");
            }

        };
    }
}
